﻿namespace Sidvall.IdentityManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class AspNetRoles : global::Sidvall.IdentityManager.UI.Entities.Core.BusinessBase, global::Sidvall.IdentityManager.Data.IAspNetRoles
    {
        #region Business Members

        #region Id

        private string _Id = null;
        partial void OnBeforeIdPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public string Id
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Id);
                OnBeforeIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Id);
                OnBeforeIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Id", eventData.Value, true, true, true);
                    OnAfterIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Name

        private string _Name = string.Empty;
        partial void OnBeforeNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Name);
                OnBeforeNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                OnBeforeNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Name", eventData.Value, true, true, true);
                    OnAfterNamePropertyChanged();
                }
            }
        }

        #endregion
        #region AspNetUsers

        private AspNetUsersCollection _AspNetUsers;
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public AspNetUsersCollection AspNetUsers
        {
            get
            {
                return _AspNetUsers;
            }
            internal set
            {
                LoadInstanceField("AspNetUsers", value, true, false, false);
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.GetKey(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.AcceptChanges(this);
        }

        #endregion
        #region Clone

        public AspNetRoles Clone()
        {
            var copySettings = Sidvall.Data.CopySettings.Clone();
            return Copy(copySettings);
        }

        #endregion
        #region Copy

        public AspNetRoles Copy()
        {
            return Copy(null);
        }
        public AspNetRoles Copy(Sidvall.Data.CopySettings copySettings)
        {
            if (copySettings == null)
                copySettings = new Sidvall.Data.CopySettings();
            if (!Sidvall.Data.DataRowContextManager.IsValid(this, copySettings.RowFilter))
                return null;
            var item = new AspNetRoles();
            Import(item, this, copySettings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.IdentityManager.Data.IAspNetRoles item)
        {
            Import(item, null);
        }
        public void Import(global::Sidvall.IdentityManager.Data.IAspNetRoles item, Sidvall.Data.CopySettings copySettings)
        {
            Import(this, item, copySettings);
        }
        partial void OnAfterImport(AspNetRoles destination, global::Sidvall.IdentityManager.Data.IAspNetRoles source, Sidvall.Data.CopySettings copySettings);
        private void Import(AspNetRoles destination, global::Sidvall.IdentityManager.Data.IAspNetRoles source, Sidvall.Data.CopySettings copySettings)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.Import(destination, source, copySettings);
            OnAfterImport(destination, source, copySettings);
        }
        partial void OnAfterImport(AspNetRoles destination, AspNetRoles source, Sidvall.Data.CopySettings copySettings);
        private void Import(AspNetRoles destination, AspNetRoles source, Sidvall.Data.CopySettings copySettings)
        {
            Import(destination, source as global::Sidvall.IdentityManager.Data.IAspNetRoles, copySettings);
            OnAfterImport(destination, source, copySettings);
        }

        #endregion
        #region SaveItemAsync

        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync()
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveMode mode)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, mode);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveSettings settings)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, settings);
        }
        public async System.Threading.Tasks.Task<AspNetRoles> SaveItemAsync(Sidvall.Data.SaveSettings settings, string strategyContext, global::Sidvall.Data.ObjectParameterCollection objectParameters)
        {
            return await global::Sidvall.IdentityManager.UI.SystemContext.Current.DataPortal.AspNetRolesManager.SaveItemAsync(this, settings, strategyContext, objectParameters);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.ValidateAsync(this, context);
            await ValidateAsync(context);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync();
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.IdentityManager.UI.SystemContext.Current.EntityFacade.AspNetRolesManager.Initialize(this, settings);
        }

        #endregion
        
        #region IAspNetRoles Members

        string global::Sidvall.IdentityManager.Data.IAspNetRoles.Id
        {
            get
            {
                return this._Id;
            }
            set
            {
                this._Id = value;
            }
        }
        string global::Sidvall.IdentityManager.Data.IAspNetRoles.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        System.Collections.Generic.IEnumerable<global::Sidvall.IdentityManager.Data.IAspNetUsers> global::Sidvall.IdentityManager.Data.IAspNetRoles.AspNetUsers
        {
            get
            {
                return this._AspNetUsers;
            }
        }
        void global::Sidvall.IdentityManager.Data.IAspNetRoles.SetAspNetUsers(Sidvall.Data.IDataRowProvider<global::Sidvall.IdentityManager.Data.IAspNetUsers> items)
        {
            UpdateChildProperty(this._AspNetUsers, items);
            this._AspNetUsers = items as AspNetUsersCollection;
        }

        #endregion

        #endregion
        #region Constructors

        public AspNetRoles()
        {
        }

        public AspNetRoles(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}